<?php
namespace app\api\controller;

use app\BaseController;
use think\facade\Request;

class common extends BaseController
{
    public function __construct()
    {


        /**
         * 设置请求头和跨域操作
         */
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Headers: Origin,user,token,time,X-Requested-With,Content-Type Accept, Authorization");
        header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS');
        if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
            exit;
        }
//        dump(1);
//        exit();
        /**
         * 与前端实现的时候在打开
         */

    }
    public function getThisUser(){
        $header = Request::header();
        $data = $header['user'];
        //base64_decode解析前端用户数据
        $str = base64_decode($data);
        $user = json_decode($str,true);

        $ecdata['uid'] = intval(base64_decode(openssl_decrypt($user['uid'], 'DES-ECB', $user['token'], 0)));
        $ecdata['role_id'] = intval(openssl_decrypt($user['role_id'], 'DES-ECB', $user['token'], 0));

        return $ecdata;
    }
}
